﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using ZG_member.BLL;
using ZG_member.Model;

namespace ZG_member
{
    public partial class TaoCanfangan : Form
    {
        string kapianid = "";
        BLL.memberInfo mi = new BLL.memberInfo();
        Model.memberInfo modle;
        int typeId = 0;
        BLL.taocanjiluBLL tcjlbll = new taocanjiluBLL();
        VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter vnp;
        List<string> goumaiGDID = new List<string>();
        MainForm mainForm;
        string memberIds = "";
        public TaoCanfangan(string id,string memberId, VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter VNp, MainForm main)
        {
            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
            kapianid = id;
            vnp = VNp;
            mainForm = main;
            memberIds = memberId;
            if (kapianid != "")
            {
                modle = mi.GetModeCard(kapianid);
            }
            else
            {
                modle = mi.GetModels(memberId);
            }
        }
        //public TaoCanfangan(int typeid, VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter VNp, MainForm main)
        //{
        //    InitializeComponent();
        //    skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
        //    this.Opacity = 0;
        //    typeId = typeid;
        //    mainForm = main;
        //    vnp = VNp;

        //}
        //public TaoCanfangan(int typeid)
        //{
        //    InitializeComponent();
        //    skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
        //    this.Opacity = 0;
        //    kapianid = typeid.ToString();
        //}
        BLL.goodsType gt = new BLL.goodsType();
        BLL.consumeSolution cs = new BLL.consumeSolution();
        BLL.goods goodbll = new BLL.goods();
        Model.goods goodMode = new Model.goods();
        double zhehoujiaqian = 0;
        double zheqianjiaqian = 0;
        private void TaoCanfangan_Load(object sender, EventArgs e)
        {
            zhehoujiaqian = 0;
            this.timer1.Start();
            Model.consumeSolution csmodle;

            if (modle == null)
            {
                List<Model.goodsType> gg = gt.GetModelList("");


                csmodle = cs.GetModel(typeId);
                this.txtKaleixing.Text = csmodle.solutionName;
                this.txtKazhekou.Text = (Convert.ToDouble(csmodle.discountSolution) / 10).ToString();




                if (csmodle == null)
                {
                    MessageBox.Show("请您先添加消费方案！");
                    this.Close();
                    return;
                }
                if (gg.Count > 0)
                {
                    this.cbogoodtype.DataSource = gg;
                    this.cbogoodtype.DisplayMember = "typeName";
                    this.cbogoodtype.ValueMember = "id";
                    this.cbogoodtype.SelectedIndex = 0;
                    jilian();
                }
                if (csmodle.Taocanxiangqing != "" && csmodle.Taocanxiangqing != null)
                {
                    string[] liebiao = csmodle.Taocanxiangqing.Split('|');
                    for (int i = 0; i < liebiao.Length; i++)
                    {
                        if (liebiao[i] == "")
                        {
                            return;
                        }
                        string[] liebiaoxiangqing = liebiao[i].Split(',');
                        Model.goods goodmodle = goodbll.getModelGoodsIdString(liebiaoxiangqing[0]);
                        if (goodmodle == null)
                        {
                            continue;
                        }
                        string[] jiazailiebiao = { liebiaoxiangqing[0], goodmodle.goodsName, liebiaoxiangqing[1], goodmodle.unit };

                        this.dataGridView1.Rows.Add(jiazailiebiao);
                    }
                }

            }
            else
            {
                this.dataGridView1.Rows.Clear();
                BLL.goods goodbll = new BLL.goods();
                List<Model.goodsType> gg = gt.GetModelList("");
                csmodle = cs.GetModel((int)modle.cardType);
                this.txtKaleixing.Text = csmodle.solutionName;
                this.txtKazhekou.Text = (Convert.ToDouble(csmodle.discountSolution) / 10).ToString();
                Model.taocanjilu tcjimodle = tcjlbll.GetModelFormemberCardId(modle.memberId);
                if (gg.Count > 0)
                {
                    this.cbogoodtype.DataSource = gg;
                    this.cbogoodtype.DisplayMember = "typeName";
                    this.cbogoodtype.ValueMember = "id";
                    this.cbogoodtype.SelectedIndex = 0;
                    jilian();
                }


                if (tcjimodle == null)
                {
                    return;
                }
                if (tcjimodle.Xiangqing != "" && tcjimodle.Xiangqing != null)
                {
                    string[] liebiao = tcjimodle.Xiangqing.Split('|');
                    for (int i = 0; i < liebiao.Length; i++)
                    {
                        if (liebiao[i] == "")
                        {
                            return;
                        }
                        string[] liebiaoxiangqing = liebiao[i].Split(',');
                        Model.goods goodmodle = goodbll.getModelGoodsIdString(liebiaoxiangqing[0]);
                        if (goodmodle == null)
                        {
                            continue;
                        }

                        string[] jiazailiebiao = { liebiaoxiangqing[0], goodmodle.goodsName, liebiaoxiangqing[1], goodmodle.unit };

                        this.dataGridView1.Rows.Add(jiazailiebiao);
                    }
                }
            }

        }

        public void print()
        {
            DialogResult dt = MessageBox.Show("是否打印？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (dt == DialogResult.Yes)
            {
                string mima = "";
                string status = "";
                try
                {
                    mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());
                    //mima = "FFFFFFFFFFFF";
                    status = vnp.RfidCardRequestAndReadData("1", mima);
                }
                catch (Exception)
                {

                    MessageBox.Show("此卡不是本公司的卡片！请与本公司联系。电话：010-51291008");
                    return;
                }

                if (status == "0" || status == "1")
                {


                    MessageBox.Show("机器内没有卡，请插卡");
                }
                BLL.consumeSolution cs = new BLL.consumeSolution();
                Model.consumeSolution css = new Model.consumeSolution();
                css = cs.GetModel(Convert.ToInt32(modle.cardType));
                MemberSaleForm ms = new MemberSaleForm(mainForm,modle.memberCardId, modle.memberId, vnp);
                string memberStatus = "";
                if (modle.status == 0)
                {
                    memberStatus = "正常";
                }
                if (modle.status ==1)
                {
                    memberStatus = "挂失";
                }
                if (modle.status == 2)
                {
                    memberStatus = "停用";
                }
                //会员卡号#会员等级#会员姓名#性　　别#卡片状态#办卡日期                                                                                                                                             #截止日期                                                    #累计积分#本次积分#可用积分#本次消费#储值余额#折扣金额                                                                                                                  #本次充值#积分支付#现金消费#空　　行
                string[] ModelArray = new string[] { modle.memberId, css.solutionName, modle.memberName, modle.sex == true ? "男" : "女", memberStatus, Convert.ToDateTime(modle.createDate).ToString("yyyy-MM-dd"),Convert.ToDateTime(modle.expiresDate).ToString("yyyy-MM-dd"),modle.point.ToString(), "0","0",this.txtShikou.Text, modle.Balance.ToString(),(Convert.ToDouble(this.txtYingkou.Text)-Convert.ToDouble(this.txtShikou.Text)).ToString(),"0", "0","0","" };
                string Go = ms.print(ModelArray);
                Go = "\n" + Go;
                Model.memberInfo mode = ms.GetModel();
                int Nowday = DateTime.Now.Day;
                int Nowyue = DateTime.Now.Month;

                int shengriday = ((DateTime)mode.birthDay).Day;
                int shengriyue = ((DateTime)mode.birthDay).Month;
                ZG_member.BLL.birthdayremind br = new ZG_member.BLL.birthdayremind();
                Model.birthdayremind brmodl = br.GetModel(2);
                int aa = br.tixingday(modle.memberId);
                if (aa < brmodl.Remindday && aa != 0)
                {
                    if (Nowyue == shengriyue)
                    {
                        if (Nowday < shengriday)
                        {
                            string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                            string two = one.Replace("{leftDays}", aa.ToString());
                            Go += two + "\n";
                        }
                    }
                    if (Nowyue < shengriyue)
                    {
                        string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd") + "\n");
                        string two = one.Replace("{leftDays}", aa.ToString());
                        Go += two + "\n";
                    }
                }
                else if (aa == 0)
                {
                    Go += ms.AdvPreProcess(brmodl.Nowremindcontent1) + "\n"; ;
                }
                vnp.PrintBufferClear();
                Application.DoEvents();
                vnp.PrintCharacterDataSetting(Go);
                Application.DoEvents();
                vnp.ErasePrintDischarge3();
            }
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }
        int flag = 0;
        private void TaoCanfangan_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }
        BLL.goods g = new BLL.goods();

        public void jilian()
        {
            try
            {
                //List<Model.goods> gg = g.GetModelList("goodstypeid = " + this.cbogoodtype.SelectedValue);
                DataTable gg= g.GetList("goodstypeid = " + this.cbogoodtype.SelectedValue).Tables[0];
                if (gg.Rows.Count <= 0)
                {
                    MessageBox.Show("没有该分类的商品！");
                    return;
                }
                this.cbogoodname.DataSource = gg;
                this.cbogoodname.DisplayMember = "goodsName";
                this.cbogoodname.ValueMember = "goodsid";
                this.cbogoodname.SelectedIndex = 0;
            }
            catch (Exception)
            {

                return;
            }
            
            //this.cbogoodname.SelectedIndex = 0;
        }

        private void cbogoodtype_SelectedIndexChanged(object sender, EventArgs e)
        {

            jilian();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.numericUpDown1.Value <= 0)
            {
                MessageBox.Show("请输入数量！");
                return;
            }

            //goumaiGDID.Add(cbogoodname.SelectedValue.ToString() + "," + numericUpDown1.Value+"|");
            ZG_member.BLL.consumeSolution consume = new ZG_member.BLL.consumeSolution();
            ZG_member.Model.consumeSolution consumeMode = new ZG_member.Model.consumeSolution();
            ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            if (modle != null)
            {
                consumeMode = consume.GetModel(Convert.ToInt32(modle.cardType));
            }


            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells["goodname"].Value.ToString() == this.cbogoodname.Text)
                {
                    goodsMode = goods.GetModelName(this.cbogoodname.Text);
                    dataGridView1.Rows[i].Cells["goodcount"].Value = (Convert.ToInt32(dataGridView1.Rows[i].Cells["goodcount"].Value) + Convert.ToInt32(this.numericUpDown1.Value));
                    int fx = 0;
                    for (int p = 0; p < goumaiGDID.Count; p++)
                    {
                        if (goumaiGDID[p].Substring(0, goumaiGDID[p].IndexOf(',')) == goods.GetModelName(this.cbogoodname.Text).goodsId)
                        {
                            int tianjiahoushuliang = Convert.ToInt32(goumaiGDID[p].Substring(goumaiGDID[p].IndexOf(',') + 1)) + Convert.ToInt32(this.numericUpDown1.Value) * Convert.ToInt32(goodsMode.amount);
                            string oop = goumaiGDID[p].Substring(goumaiGDID[p].IndexOf(','));
                            goumaiGDID[p] = goumaiGDID[p].Replace(oop, "," + tianjiahoushuliang.ToString());
                            break;
                        }
                        fx++;
                    }
                    if (fx == goumaiGDID.Count)
                    {
                        goumaiGDID.Add(goods.GetModelName(this.cbogoodname.Text).goodsId.ToString() + "," + (Convert.ToInt32(this.numericUpDown1.Value) * Convert.ToInt32(goodsMode.amount)).ToString() + "");
                    }


                    if (modle != null)
                    {

                        goodsMode = goods.getModelGoodsIdString(this.cbogoodname.SelectedValue.ToString());
                        zheqianjiaqian += Convert.ToDouble(goodsMode.price) * Convert.ToInt32(this.numericUpDown1.Value);


                        if (consumeMode.cuxiaozhekou == true && goodsMode.Promotion == true)
                        {
                            zhehoujiaqian = zheqianjiaqian * Convert.ToDouble(goodsMode.Promotionprice) / 100;
                        }
                        else
                        {
                            //if (goodsMode.GlobalDiscount == true)
                            //{
                            //    zhehoujiaqian = zheqianjiaqian * Convert.ToDouble(goodsMode.Promotionprice) / 100;
                            //}
                            //else
                            //{
                            //    zhehoujiaqian = zheqianjiaqian;
                            //}
                        }




                        //zhehoujiaqian += Convert.ToDouble(goodsMode.price) * Convert.ToInt32(this.numericUpDown1.Value) * (Convert.ToDouble(consumeMode.discountSolution) / 100);
                        this.txtYingkou.Text = zheqianjiaqian.ToString();
                        this.txtShikou.Text = zhehoujiaqian.ToString();

                    }
                    return;
                }
            }
            goodsMode = goods.GetModelName(this.cbogoodname.Text);

            if (Convert.ToInt32(this.numericUpDown1.Value) > Convert.ToInt32(goodsMode.amount))
            {
                MessageBox.Show("超出商品数量！");
                return;
            }
     

            //string[] tiaojian = { this.cbogoodname.SelectedValue.ToString(), this.cbogoodname.Text, (Convert.ToInt32(this.numericUpDown1.Value) * Convert.ToInt32(goodsMode.amount)).ToString() };
            string[] tiaojian = { this.cbogoodname.SelectedValue.ToString(), this.cbogoodname.Text,this.numericUpDown1.Value.ToString() };

            this.dataGridView1.Rows.Add(tiaojian);
            goumaiGDID.Add(goods.GetModelName(this.cbogoodname.Text).goodsId.ToString() + "," + Convert.ToInt32(this.numericUpDown1.Value).ToString() + "");

            

            if (modle != null)
            {
                zheqianjiaqian += Convert.ToDouble(goodsMode.price) * Convert.ToInt32(this.numericUpDown1.Value);
                if (consumeMode.cuxiaozhekou == true && goodsMode.Promotion == true)
                {
                    zhehoujiaqian = zheqianjiaqian * Convert.ToDouble(goodsMode.Promotionprice) / 100;
                }
                else
                {
                    //if (goodsMode.GlobalDiscount == true)
                    //{
                    //    zhehoujiaqian = zheqianjiaqian * Convert.ToDouble(goodsMode.Promotionprice) / 100;
                    //}
                    //else
                    //{
                    //    zhehoujiaqian = zheqianjiaqian;
                    //}
                }

                this.txtYingkou.Text = zheqianjiaqian.ToString();
                this.txtShikou.Text = zhehoujiaqian.ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            zhehoujiaqian = 0;
            zheqianjiaqian = 0;
            this.txtShikou.Text = "0";
            this.txtYingkou.Text = "0";
            goumaiGDID.Clear();
            this.dataGridView1.Rows.Clear();
        }



        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            ZG_member.BLL.consumeSolution consume = new ZG_member.BLL.consumeSolution();
            ZG_member.Model.consumeSolution consumeMode = new ZG_member.Model.consumeSolution();

            for (int i = 0; i < goumaiGDID.Count; i++)
            {
                if (dataGridView1.CurrentRow.Cells["goodsid"].Value.ToString() == goumaiGDID[i].Substring(0, goumaiGDID[i].IndexOf(',')))
                {

                    goodsMode = goods.getModelGoodsIdString(dataGridView1.CurrentRow.Cells["goodsid"].Value.ToString());
                    int shuliang = Convert.ToInt32(goumaiGDID[i].ToString().Substring(goumaiGDID[i].ToString().IndexOf(',') + 1));
                    double jiage = Convert.ToDouble(goodsMode.price) * shuliang * (Convert.ToDouble(consume.GetModel(Convert.ToInt32(modle.cardType)).discountSolution) / 100);
                    zhehoujiaqian = zhehoujiaqian - Convert.ToDouble(goodsMode.price) * shuliang * (Convert.ToDouble(consume.GetModel(Convert.ToInt32(modle.cardType)).discountSolution) / 100);
                    zheqianjiaqian = zheqianjiaqian - Convert.ToDouble(goodsMode.price) * shuliang;
                    this.txtYingkou.Text = zheqianjiaqian.ToString();
                    this.txtShikou.Text = zhehoujiaqian.ToString();
                    goumaiGDID.RemoveAt(i);
                    break;
                }
            }

            this.dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (modle == null)
            {

                //if(modle.Balance<Convert.ToDecimal(zhehoujiaqian))
                //{
                //    MessageBox.Show("卡内金额不足，请充值！");
                //    return;
                //}

                string taocanxiangqing = "";

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    taocanxiangqing += dataGridView1.Rows[i].Cells["goodsid"].Value.ToString() + "," + dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() + "|";
                }




                if (cs.Updatetaocan(taocanxiangqing, typeId.ToString()))
                {
                    MessageBox.Show("保存成功！");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败！");
                }
            }
            else
            {
                //string taocanxiangqing = "";
                //for (int i = 0; i < dataGridView1.Rows.Count; i++)
                //{
                //    taocanxiangqing += dataGridView1.Rows[i].Cells["goodsid"].Value.ToString() + "," + dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() + "|";
                //}
                //if (cs.Updatetaocan(taocanxiangqing, modle.cardType.ToString()))
                //{
                //    MessageBox.Show("保存成功！");
                //    this.Close();
                //}
                //else
                //{
                //    MessageBox.Show("保存失败！");
                //}
                //===================
                if (this.txtShikou.Text == "")
                {
                    MessageBox.Show("金额不能为空！");
                    return;
                }
                if (modle.Balance < Convert.ToDecimal(this.txtShikou.Text))
                {
                    MessageBox.Show("卡内金额不足，请充值！");
                    return;
                }
                //if (txtYingkou.Text.Trim() == "")
                //{
                //    MessageBox.Show("请购买商品后在保存信息！");
                //    return;
                //}
                Model.taocanjilu tcmodle = new Model.taocanjilu();
                tcmodle.Memberid = modle.memberId.Trim();
                BLL.goods goods = new BLL.goods();
                Model.goods goodsMode = new Model.goods();



                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    goodsMode = goods.getModelGoodsIdString(dataGridView1.Rows[i].Cells["goodsid"].Value.ToString());
                    tcmodle.Xiangqing += dataGridView1.Rows[i].Cells["goodsid"].Value.ToString() + "," + dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() + "|";
                }
                int CountCourseNum = 0;
                for (int i = 0; i < goumaiGDID.Count; i++)
                {
                    CountCourseNum += Convert.ToInt32(goumaiGDID[i].Substring(goumaiGDID[i].IndexOf(',') + 1));
                }

                ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
                modle.Balance = modle.Balance - Convert.ToDecimal(this.txtShikou.Text);
                member.Update(modle);
                ZG_member.BLL.wasteBook waste = new ZG_member.BLL.wasteBook();
                ZG_member.Model.wasteBook wastebookModel = new ZG_member.Model.wasteBook();
                wastebookModel.memberCardId = modle.memberId;
                wastebookModel.consumeTimes = "1";
                wastebookModel.operatorId = MainForm.Operator;
                wastebookModel.consumeType = modle.cardType;
                wastebookModel.cardPayMoney = Convert.ToDecimal((this.txtShikou.Text));
                wastebookModel.cashPayMoney = 0;
                wastebookModel.consumeMoney = Convert.ToDecimal(this.txtShikou.Text);
                wastebookModel.consumeIntegral = 0;
                wastebookModel.totalIntegral = modle.point;
                wastebookModel.exchangeIntegral = 0;
                wastebookModel.savingMoney = 0;
                wastebookModel.refundmentIntegral = 0;
                wastebookModel.refundmentMoney = 0;
                //wastebookModel.cardBalance = decimal.Parse(this.TxtBalance.Text) + decimal.Parse(TxtCardPay.Text);
                wastebookModel.cardBalance = modle.Balance;
                wastebookModel.date = DateTime.Parse(DateTime.Now.ToString());
                wastebookModel.details = ConfigurationManager.AppSettings["details"];
                wastebookModel.terminalId = "0";
                wastebookModel.Jiedairen = MainForm.Operator;
                waste.Add(wastebookModel);

                BLL.goodsInfo goodsinfo = new BLL.goodsInfo();
                Model.goodsInfo goodMode = new Model.goodsInfo();
                string MaxWasteID = waste.GetMaxId().ToString();
                for (int i = 0; i < goumaiGDID.Count(); i++)
                {
                    goodMode.Gid = goumaiGDID[i].Substring(0, goumaiGDID[i].IndexOf(','));
                    goodMode.Goodscount = Convert.ToInt32(goumaiGDID[i].Substring(goumaiGDID[i].IndexOf(',') + 1));
                    goodsMode = goods.getModelGoodsIdString(goodMode.Gid);
                    goodMode.Goodsprice = Convert.ToDecimal(goodMode.Goodscount / goodsMode.amount * goodsMode.price) * (Convert.ToDecimal(this.txtKazhekou.Text) / 10);
                    goodMode.Selltime = DateTime.Now.ToString();
                    goodMode.Zhekou = (Convert.ToInt32(this.txtKazhekou.Text) * 10).ToString();
                    goodMode.wasteBookId = Convert.ToInt32(MaxWasteID);
                    goodsinfo.add(goodMode);
                }

                if (tcjlbll.Exists(modle.memberId.Trim()))
                {
                    if (tcjlbll.updatexiangqing(tcmodle) > 0)
                    {
                        MessageBox.Show("保存成功！");
                        if (kapianid != "")
                        {
                            print();
                        }
                    }
                }
                else
                {

                    if (tcjlbll.Add(tcmodle) > 0)
                    {
                        MessageBox.Show("保存成功！");
                        if (kapianid != "")
                        {
                            print();
                        }
                    }
                }
                this.Close();


            }


        }

        private void cbogoodname_TextUpdate(object sender, EventArgs e)
        {
            //string goodsName = this.cbogoodname.Text;
            //BLL.goods goods = new BLL.goods();
            //DataTable dt = goods.GetList("goodsName like '%" + goodsName + "%'").Tables[0];
            //cbogoodname.DataSource = dt;
            //cbogoodname.DisplayMember = "goodsName";
            //cbogoodname.ValueMember = "goodsId";
            //this.cbogoodname.Text = goodsName;
            //cbogoodname.DroppedDown = true;
            //Cursor = Cursors.Default;
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick_1(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }

        private void cbogoodtype_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
                cbogoodname.DataSource = goods.GetList(" goodsTypeId = '" + this.cbogoodtype.SelectedValue + "'").Tables[0];
                cbogoodname.DisplayMember = "goodsName";
                cbogoodname.ValueMember = "goodsid";
            }
            catch (Exception)
            {
                
           
            }
           
        }

        private void dataGridView1_CellMouseDoubleClick_1(object sender, DataGridViewCellMouseEventArgs e)
        {
            string goodsid = dataGridView1.CurrentRow.Cells["goodsid"].Value.ToString();
            ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            ZG_member.BLL.consumeSolution consu = new ZG_member.BLL.consumeSolution();
            ZG_member.Model.consumeSolution consuMode = new ZG_member.Model.consumeSolution();
            goodsMode = goods.getModelGoodsIdString(goodsid);
            consuMode=consu.GetModel(Convert.ToInt32(modle.cardType));
            double shikou = 0;
            double yingkou = 0;
            //if (goodsMode.GlobalDiscount == true)
            //{
            //    shikou = Convert.ToDouble(goodsMode.price * Convert.ToInt32(goodsMode.Promotionprice));
            //}
            //else
            //{
            //    if (goodsMode.Promotion == true && consuMode.cuxiaozhekou == true)
            //    {
            //        shikou = Convert.ToDouble(goodsMode.price * Convert.ToInt32(goodsMode.Promotionprice));
            //    }
            //    else
            //    {
            //        shikou = Convert.ToDouble(goodsMode.price * 1);
            //    }
            //}
            yingkou = Convert.ToDouble(goodsMode.price * 1);
            try
            {
                this.txtShikou.Text = (Convert.ToDouble(this.txtShikou.Text) - shikou).ToString();
            }
            catch (Exception)
            {
                this.txtShikou.Text ="0";
            }
            try
            {
                this.txtYingkou.Text = (Convert.ToDouble(this.txtYingkou.Text) - yingkou).ToString();
            }
            catch (Exception)
            {

                this.txtYingkou.Text = "0";
            }
            
            dataGridView1.Rows.Remove(dataGridView1.CurrentRow);

            
        }
    }
}
